﻿#include "HellBomb.h"
#include "../../Settings.h"
#include "../../MirEnvir/Envir.h"
#include "../../../Shared/ServerPackets.h"
#include "../DelayedAction.h"
#include "../../../Shared/Data/Stat.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool HellBomb::getCanMove() const
    {
        return false;
    }

    bool HellBomb::getCanRegen() const
    {
        return false;
    }

    HellBomb::HellBomb(MonsterInfo *info) : MonsterObject(info)
    {
        ExplosionTime = getEnvir()->getTime() + (10 * Settings::Second);
        setDirection(MirDirection::Up);
    }

    void HellBomb::FindTarget()
    {
    }

    void HellBomb::Turn(MirDirection dir)
    {
    }

    bool HellBomb::Walk(MirDirection dir)
    {
        return false;
    }

    void HellBomb::ProcessRegen()
    {
    }

    void HellBomb::ProcessSearch()
    {
    }

    void HellBomb::ProcessRoam()
    {
    }

    void HellBomb::ApplyPoison(Poison *p, MapObject *Caster, bool NoResist, bool ignoreDefence)
    {
    }

    int HellBomb::Struck(int damage, DefenceType type)
    {
        return 0;
    }

    void HellBomb::ProcessTarget()
    {
        if (getEnvir()->getTime() > ExplosionTime)
        {
            Die();
            return;
        }
    }

    void HellBomb::Die()
    {
        if (HP > 0)
        {
            S::ObjectAttack *tempVar = new S::ObjectAttack();
            tempVar->ObjectID = ObjectID;
            tempVar->Direction = getDirection();
            tempVar->Location = getCurrentLocation();
            Broadcast(tempVar);
            DelayedAction tempVar2(DelayedType::Die, getEnvir()->getTime() + 500);
            ActionList.push_back(&tempVar2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }

        MonsterObject::Die();
    }

    void HellBomb::CompleteDeath(std::vector<std::any> &data)
    {
        std::vector<MapObject*> targets = FindAllTargets(4, getCurrentLocation(), false);
        if (targets.empty())
        {
            return;
        }

        for (int i = 0; i < targets.size(); i++)
        {
            int damage = GetAttackPower(Stats[Stat::MinDC], Stats[Stat::MaxDC]);
            if (damage == 0)
            {
                return;
            }

            if (targets[i]->Attacked(this, damage, DefenceType::AC) <= 0)
            {
                continue;
            }

            switch (Info->Image)
            {
                case Monster::HellBomb1:
                    PoisonTarget(targets[i], 1, 5, PoisonType::Frozen, 2000);
                    break;
                case Monster::HellBomb2:
                    PoisonTarget(targets[i], 1, 5, PoisonType::Dazed, 2000);
                    break;
                case Monster::HellBomb3:
                    PoisonTarget(targets[i], 1, 5, PoisonType::Bleeding, 2000);
                    break;
            }
        }
    }
}
